pub struct Solution;

impl Solution {
    pub fn equal_substring(s: String, t: String, max_cost: i32) -> i32 {
        let s = s.as_bytes();
        let t = t.as_bytes();
        let mut i = 0;

        let mut max_cost = max_cost;

        for (a, b) in s.iter().zip(t.iter()) {
            max_cost -= (*a as i32 - *b as i32).abs();
            if max_cost < 0 {
                max_cost += (s[i] as i32 - t[i] as i32).abs();
                i += 1;
            }
        }

        (s.len() - i) as i32
    }
}


fn main() {
    let s = "abcdaab";
    let t = "bcdezbc";
    let max_cost = 4;
    let res = Solution::equal_substring(s.to_string(), t.to_string(), max_cost);

    println!("{}", res);
}
